<template>
  <div class="collectrent content-bg">
    <el-table :data="tableData"
              border
              :fit="true"
              style="width: 100%">
      <el-table-column label="房屋id"
                       prop="id" width="100">
      </el-table-column>
      <el-table-column label="地址"
                       prop="address" width="280">
      </el-table-column>
      <el-table-column label="租金"
                       prop="price">
      </el-table-column>
      <el-table-column label="租赁人"
                       prop="name">
      </el-table-column>
      <el-table-column label="租赁人身份证号码"
                       prop="applyNumber">
      </el-table-column>
      <el-table-column label="租赁人联系电话"
                       prop="phone">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini"
                     type="primary"
                     @click="collectRent(scope.$index, scope.row)">收租</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-box">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagination.currentPage"
        :page-size="pagination.pageSize"
        layout="total, prev, pager, next"
        :total="pagination.total">
      </el-pagination>
    </div>
    <!-- 收租弹框 -->
    <el-dialog title="收租"
              :visible.sync="dialogVisible"
               width="40%"
               :before-close="handleClose">
      <el-form ref="form"
             :model="form"
             :rules="rules"
             label-width="150px">
      <el-form-item label="房屋id" prop="id">
        <el-input v-model="form.id"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="form.address"></el-input>
      </el-form-item>
      <el-form-item label="租客姓名" prop="renter">
        <el-input v-model="form.renter"></el-input>
      </el-form-item>
      <el-form-item label="租金交付日期截止"  prop="date">
        <el-input v-model="form.date"></el-input>
      </el-form-item>
      <el-form-item label="应缴租金"  prop="price">
        <el-input v-model="form.price"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   @click="onSubmit">提交</el-button>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
    </el-dialog>
  </div>
</template>
<script lang="js">
import axios from "axios";

export default {
    data(){
      return{
        tableData: [],
        form: {
          id: '13213',
          address: 'xxx',
          renter: 'xx',
          date: '2023-4-5',
          price: 800
        },
        rules: {
          id: [
            { required: true, message: '请输入房屋id', trigger: 'blur' },
            { min: 3, max: 8, message: '长度在3到8个字符之间', trigger: 'blur' }
          ],
          address:[
          { required: true, message: '请输入房屋地址', trigger: 'blur' },
            { min: 5, max: 30, message: '长度在 5 到 30个字符', trigger: 'blur' }
          ],
          renter:[
          { required: true, message: '请输入房屋面积', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
          ],
          date:[
          { required: true, message: '请输入房屋租金', trigger: 'blur' },
            { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '请选择房屋状态', trigger: 'change' }
          ]},
          dialogVisible: false,
        pagination: {//分页相关模型数据
          currentPage: 1,//当前页码
          pageSize: 10,//每页显示的记录数
          total: 0,//总记录数
          type:"",
          name:"",
          description:"",
        }
      }
    },
  created() {
      this.getAll()
  },
  methods: {
      getAll: function (){
        axios.get("/topaid/manage/"+this.pagination.currentPage).then((res)=>{
          if (res.data.code === 1){
            this.tableData = res.data.data.records
            this.pagination.currentPage = res.data.data.current
            this.pagination.total = res.data.data.total
            this.pagination.pageSize = res.data.data.size
          }
        })
      },
      collectRent(index, row) {
        this.dialogVisible = true;
      },
      handleClose(){
        this.dialogVisible = false;
      },
      onSubmit(){
        // 访问接口
        this.dialogVisible = false;
      },
      // 返回
      goBack(){
        this.dialogVisible = false;
      },
      //切换页码
      handleCurrentChange(currentPage) {
        this.pagination.currentPage = currentPage;
        this.getAll();
      },
    }

}
</script>
<style lang="scss" scoped>
.house-form {
  // width: calc(100% - 300px);
  background: #fff;
  padding: 10px;
  padding-right: 20px;
}
</style>
